#+TITLE:Emacs Cheatsheat
#+AUTHOR:Joshua Branson
#+LATEX_HEADER: \usepackage{lmodern}
#+LATEX_HEADER: \usepackage[QX]{fontenc}
#+OPTIONS: H:10 toc:nil

* Built in Emacs Features
** Advising a named Function
[[info:elisp#Advising%20Named%20Functions][info:elisp#Advising Named Functions]]
** Bookmarks
  Emacs bookmarks are nifty ways of saving your place in a file.

  - =C-x r m=  sets a bookmark for you at point and it prompts you to name it
  - =C-x r b=  jumps you to a bookmark
** dired
Dired is the emacs file manager.  It opens a buffer displaying all your files in the specified directory.  With it you can perform numerous commands on marked files, like deleting, copying, moving, or even creating your own command.
*** commands
  - ~n~ next line
  - ~p~ previous line
  - ~m~ mark the current file under point
  - ~u~ unmark the current file under point
  - ~* /~ mark all directories
  - ~* *~ mark all executables
  - ~* s~ mark all files in the current sub-directory
  - ~% m REGEXP <RET>  mark files based on a regular expression
  - ~Q~ dired-do-query-replace-regexp lets you search and replace all marked files
    -  Press y, to replace the current match
    -  press ~n~ to skip the current match
    -  press ~!~ to replace all the matches in the current buffer
    -  Press ~Y~ to replace all the remaining matches in all buffers
  - how to recursively search and replace

    M-x find-name-dired: you will be prompted for a root directory and a filename pattern, but this file name pattern uses find’s version of grep.  So it does not understand “.*“.  Instead “*” is equivalent to “.*”

    Press t to "toggle mark" for all files found.

    Press Q for "Query-Replace in Files...": you will be prompted for query/substitution regexps.

    Proceed as with query-replace-regexp: SPACE to replace and move to next match, n to skip a match, etc.

      -  Press y, to replace the current match
      -  press ~n~ to not skip the current match
      -  press ~!~ to replace all the matches in the current buffer
      -  Press ~Y~ to replace all the remaining matches without question

  - M-x wdired-change-to-wdired-mode
    Makes the contents of the dired buffer editable.  Once you are done making changes type =C-c C-c=.  This saves your changes.  It is a nifty way to easily change file permissions, file names, etc.
*** image dired
lets you view images inside dired.

Mark the images you wish to view, then press C-t d (image-dired-display-thumbs)

You could also just do a M-x image-dired
** Macros
A Macro is a remembered sequence of Emacs keychords that can be repeated.  This is useful to easily repeat similar text, or delete, edit similar text.  For example, I can write out the numbers 1 through a 100, if I hit 30 keys.  I could write the numbers 1 through 1,000 by typing 31 keys!

  - ~C-x (~ begin recording a keyboard macro
  - ~C-x )~ end recording a keyboard macro
  - ~C-x e~  performs the last created keyboard macro
  - =C-x q= prompt, when you use this macro if you want to continue.  You can enter C-r to briefly step out of the macro
    and do some edits yourself, then C-M-c will allow you to continue execution of the macro.
  - ~C-x Q~  prompt the user for input during a macro.

    # FIXME specify where I found this defun
    This is not a standard emacs command; I found it on the emacs wiki.  Essentially this command tells the macro to prompt the user for input every time you call the macro.  This is useful if you have a macro that wants to write out a convoluted sequence of numbers.  The code for this is here:

    # FIXME:  WHERE DID I find this defun?? emacs wiki?
    #+BEGIN_SRC emacs-lisp
      ;; When you define a macro, you can type C-x Q to prompt the user for input.
      ;; Very helpful and cool!
      (defun my-macro-query (arg)
        "Prompt for input using minibuffer during kbd macro execution.
          With prefix argument, allows you to select what prompt string to use.
          If the input is non-empty, it is inserted at point."
        (interactive "P")
        (let* ((query (lambda () (kbd-macro-query t)))
               (prompt (if arg (read-from-minibuffer "PROMPT: ") "Input: "))
               (input (unwind-protect
                          (progn
                            (add-hook 'minibuffer-setup-hook query)
                            (read-from-minibuffer prompt))
                        (remove-hook 'minibuffer-setup-hook query))))
          (unless (string= "" input) (insert input))))

      (global-set-key "\C-xQ" #'my-macro-query)
    #+END_SRC

*** My personal keybindings                                                   :noexport:
  - `C-c r <letter>` begin recording keyboard macro
  - `C-c r <letter>` end recording keyboard macro
  - `@ <letter>` perform keyboard macro
** narrowing
  are entered via this syntax
  ~C-x n <letter>~

  ~d~ narrow to defun
  ~r~ widen to region
  ~s~ narrow to a org subtree
  ~w~ widden to the whole buffer

  A much better way to use the narrowing commands is just to make emacs guess what you want whenever you press "C-x n", and that's what the following snippet does.  I recommend that you put it in your .emacs:

  I found this code snippet [[http://endlessparentheses.com/emacs-narrow-or-widen-dwim.html][here.]]

  #+BEGIN_SRC emacs-lisp
    ;; Also set up narrow dwin
    (defun narrow-or-widen-dwim (p)
      "Widen if buffer is narrowed, narrow-dwim otherwise.
    Dwim means: region, org-src-block, org-subtree, or defun,
    whichever applies first. Narrowing to org-src-block actually
    calls `org-edit-src-code'.

    With prefix P, don't widen, just narrow even if buffer is
    already narrowed."
      (interactive "P")
      (declare (interactive-only))
      (cond ((and (buffer-narrowed-p) (not p)) (widen))
            ((region-active-p)
             (narrow-to-region (region-beginning) (region-end)))
            ((derived-mode-p 'org-mode)
             ;; `org-edit-src-code' is not a real narrowing
             ;; command. Remove this first conditional if you
             ;; don't want it.
             (cond ((ignore-errors (org-edit-src-code))
                    (delete-other-windows))
                   ((ignore-errors (org-narrow-to-block) t))
                   (t (org-narrow-to-subtree))))
            ((derived-mode-p 'latex-mode)
             (LaTeX-narrow-to-environment))
            (t (narrow-to-defun))))

    ;; This line actually replaces Emacs' entire narrowing
    ;; keymap, that's how much I like this command. Only copy it
    ;; if that's what you want.
    (define-key ctl-x-map "n" #'narrow-or-widen-dwim)
  #+END_SRC
** Rectangles
  You can easily create a rectangle with evil mode with C-v.  Once you have a rectangle you can do these commands:

  =C-x r o= insert blank spaces to the left of the rectangle region
  =C-x r N= insert numbers all along the left of the rectangle region
** Registers
  Number Registers
  -`C-u number C-x r n r`
  Store number into register r (number-to-register).

  `C-u number C-x r + r`
  If r contains a number, increment the number in that register by number. Note that command C-x r + (increment-register) behaves differently if r contains text. See Text Registers.

  `C-x r i r`
  Insert the number from register r into the buffer.

  `C-x r i` is the same command used to insert any other sort of register contents into the buffer. `C-x r +` with no numeric argument increments the register value by 1; `C-x r n` with no numeric argument stores zero in the register.

  =C-x r s R=  save text to register R
  =M-x append-to-register R= appends text to Register R
** Selective Display
  Emacs can display portions of the buffer based on level of indentention.  This lets you get a nice overview of the file, which is quite cool.
  - =C-u n C-x $= hides rows that are indented n times
  - =C-x $=  shows all rows
** windows commands
In emacs the entire emacs program takes up a *frame*.  But emacs allows you to view two different files in the same frame, by splitting the frame in half, or in two *windows*.

  - =C-x o= Delete the selected window
  - =C-x 1= Delete all the windows except the one that currently has point
  - =C-x ^= make the selected window taller
  - =C-x {= make the selected window narrower
  - =C-x }= make the selected window wider
  - =C-x -= shrink this window if it doesn't need that many lines.
  - =C-x += make all the windows the same height
** org-mode
*** Org-mode's syntax structure
# I can learn more here:  http://orgmode.org/worg/dev/org-syntax.html
Org-mode lets you easily insert headings and sub headings with "C-RET".  If you press it many times, you'll have something like this:

#+BEGIN_SRC org :exports code
  ,*
  ,*
  ,*
  ,*
#+END_SRC

A line with just one "*" is a top level heading.  If it has a two "**" below it, then it now has a sub-heading.  Just like the following:
#+BEGIN_SRC org :exports code
  ,* I am a top level heading
  ,** I am a sub-heading.
#+END_SRC

You can use the tab key to show/hide any sub level headings.


Org-mode is also great for todo lists.  Hitting ~C-c C-t~ lets you mark an item as TODO or DONE.

# "-----"  5 hyphens in an org document makes a horizontal rule.
**** Todo lists
One can easily create simple todo lists with org-mode.  In any org file ~C-RET~ inserts a "*" into the buffer.  Pressing "C-c C-t" will add the words "TODO".  It'll look like:

#+BEGIN_SRC org :exports code
  ,* TODO
#+END_SRC

Pressing ~C-c C-t~ again, will change the status to DONE.  You will end up with something looking like:

#+BEGIN_SRC org :exports code
  ,* DONE
#+END_SRC
**** Tables

If a column in an org table contains <N>, where N is a number, then that table column will be that many characters wide.
|------------+-------+-----------------+----------------------|
| <10>       | <5>   | <15>            | <20>                 |
| I          | am    | a               | table                |
|            |       |                 |                      |
|------------+-------+-----------------+----------------------|
*** org-babel
Org babel is a the best approach towards literate programming ever attempted, and it works!  Almost all programming languages treat code as the first order citizen and hides comments behind a simple syntax.  For example here is some javascript:

#+BEGIN_SRC js :exports code
  // initialize the variable
  var i = 5;
  if (i < 6) {
    i++;
  }
  console.log (i);
#+END_SRC

The comment "initialize the variable" comes after the comment syntax "//".  In literate programming the code portion of the file is "commented" and the comments do not hide behind a comment syntax.  Let me give you an example of the literate kind:

#+BEGIN_SRC org
  Let's write a trivial js function the literate way
  ,#+BEGIN_SRC js :exports code
    var i = 5;
    if (i < 6) {
      i++;
    }
    console.log (i);
  ,#+END_SRC
#+END_SRC

#+BEGIN_SRC calc
5 + 5
#+END_SRC

#+RESULTS:
: 10

How cool is that?
**** Specific header arguments
http://orgmode.org/manual/Specific-header-arguments.html
[[info:org#Specific%20header%20arguments][info:org#Specific header arguments]]

- :results
  syntax:
  :results [raw | silent | value | output ]
  value is function mode.  It means that org-mode will use the last executed command as the value of the output.
  ie:

#+BEGIN_SRC python :results value
import time
print("Hello, today's date is %s" % time.ctime())
print('Two plus two is')
return 2 + 2
#+END_SRC

  #+RESULTS:
  : 4

#+BEGIN_SRC sh :results output
  echo "hello world"
  echo "big cat"
  ls -lh | grep emacs.org
  #+END_SRC

#+RESULTS:
: hello world
: big cat
: -rw-r----- 1 joshua 1000  28K Mar  9 14:51 emacs.org

- :exports [code | results | node | both]
- :dir
  Specify a default directory that the code is to be run in
  :dir <dir>
*** Extending Org-mode
read about org's parser here http://orgmode.org/worg/dev/org-element-api.html
* Helpful Emacs modes
** bug-hunter
   This will help you find bugs in your init file.  Ensure that you have installed bug-hunter toward the top of your init file.  That way, when something breaks later in your init file, you can run ~M-x bug-hunter-init-file~ to find the problem.

   So your init file would look like this:

   #+BEGIN_SRC emacs-lisp :exports code
     (require 'package)
     (add-to-list 'package-archives '("gnu"   . "http://elpa.gnu.org/packages/"))
     ;;; Also use Melpa for most packages
     (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
     (use-package bug-hunter :ensure t :defer t)

     ;;the rest of your init file
   #+END_SRC

  https://github.com/Malabarba/elisp-bug-hunter
** helm mode
Helm mode is a completion framework.  The default Emacs completion framework is ido-mode.  You can see ido-mode in action with ~M-x ID-find-file~.

  C-c C-f helm-find-files  and or C-x C-f

  In this mode typing "~/ manage js$"
  will display a list of files in my home directory that contain the work 'manage' and end is js
  
  Alternatively, after you have typed C-x C-f, you can then type "C-u C-s" to search recursively via rgrep.

  Or M-g a (ag) or M-g g for git-grep.

  Typing C-l will display the files is the parent directory
  Typing C-z when point is on a directory, will show the files in that directory

  Helm has nth commands. Instead of typing tab to get to the action menu
  just press C-e for the 2nd action
  and C-j for the 3rd action.
  You can also bind a key to an action menu
  (define-key helm-map (kbd "<C-tab>") 'helm-select-4th-action)

  C-c C-u lets you view an image

  Apparently helm lets you open files externally in helm-find-files with C-c C-x (not working though)

  I can make personal actions on to run on files via eshell WOW!!!!

  C-SPC will mark files that you can perform actions on

  You can then hit copy files in the action menu, which will let you select a new destionation to copy the files. so cool!
  You can do the same thing from the action menu with rename, symlink, hardlink

  helm has support for etags
  C-h e  will search the tags file
  the above should create the TAGS file with tags, but it's not working
  find . -iregex .*\.el$ | xargs etags

  check out pcomplete extension
  https://github.com/thierryvolpiatto/pcomplete-extension

*** commands
  I can also write my own helm commands cool!
  [[http://wikemacs.org/wiki/How_to_write_helm_extensions][write your own helm extentions
  ]]
  =C-c h m=  open helm-man-woman
  =C-c h h g= open helm info gnus
  =C-c h h r= open the helm-emacs-info
  =C-c h b= is helm-resume which opens up the last instance that you were on
  =M-<space>= mark candidate
  =C-h m= inside a helm window will show you all of helm's keybindings

*** helm-descbinds
** evil mode
  " <letter> yy   stores the whole line into register <letter>
  " <letter> p    puts the whole line back
  =vip= select the paragraph that point is in.

  check out filters. It lets you take a line, and throw that line as a command.
  It lets you create macros that you can take a line as a command to line in bash.
  interesting
*** filters
Evil-mode lets you put the contents of the buffer through a shell command!

   You can take a line like

   hello how are you   :.!wc -w   -->   4
   hello how are you   :.!wc -c   -->   21

   5 / 6  :.!bc -l   -->  .83333333333333333333

 5    :105,109!sort --> 1
 4                    2
 3                    3
 2                    4
 1                    5

 Sort has lots of options.  I can do sort -r by reverse order, sort -k4  the 4th column, sort -n sort numerically

** El-doc
  El-doc shows you what a function in the mini-bar as you write it.  By default it works for emacs lisp extremely well.  You'll notice that my emacs-lisp-mode-hook sharp quotes eldoc-mode, which means it's using the syntax =#'eldoc-mode=.  Sharping quoting is only necessary if you are quoting named emacs lisp functions.
#+BEGIN_SRC emacs-lisp
  (add-hook 'emacs-lisp-mode-hook #'eldoc-mode)
#+END_SRC

** COMMENT Semantic

   Most emacs modes use a bunch of regular expressions to highlight source code. BUT semantic tries to make this better by
   parsing the code and creating grammar with it.
*** User commands
    - =C-c , j= prompt for a tag in the currect file and move point to it.
    - =C-c , J= prompt for a tag in any file that emacs has parsed and move point to it.
** ttd-mode let's you specify a compile command. Everytime you save a file, it will run your compile command.
  If it finds an error, it will alert you at the bottom!
** yasnippet
http://ergoemacs.org/emacs/yasnippet_templates_howto.html
*** Important Characters
- =$&= indents the line according to the major mode
- =`(some-lisp-code)`= embods lisp code
- =$0= where point will be when the snippet ends
- =$n= where n is a number ie: =$1=, =$2=, etc.  If you have multiple $3, then typing some text in one $3 will also be put in
  the other $3.
- =${n:<placeholder text>}
** Undo tree
learn more about undo tree
** Paredit mode
http://danmidwood.com/content/2014/11/21/animated-paredit.html
Paredit mode is a superior way to interact with lisps.

*** slurping

slurping elongates the current sexp by pulling in the closest sexp (either forward or backward)

 #+BEGIN_SRC emacs-lisp
   ;; here I've called "C-c 0" paredit-forward-slurp-sexp
   ;; point was always on the "h" in hello
   ((hello) this is a nice little sentence)
   ((hello this) is a nice little sentence)
   ((hello this is) a nice little sentence)
   ((hello this is a) nice little sentence)
   ((hello this is a nice) little sentence)
   ((hello this is a nice little) sentence)
   ((hello this is a nice little sentence))

   ;; here I've called C-c 0 paredit-backward-slurp-sexp
   ;; which pulls in another sexp or atom into my current sexp
   ;; point was always on "e" in sentence
   (hello this is a nice little (sentence))
   (hello this is a nice (little sentence))
   (hello this is a (nice little sentence))
   (hello this is (a nice little sentence))
   (hello this (is a nice little sentence))
   (hello (this is a nice little sentence))
   ((hello this is a nice little sentence))
     #+END_SRC

*** barfing

barfing shortens the currect sexp by pushing out the closest sexp (either forward or backward)
 #+BEGIN_SRC emacs-lisp
   ;; here I've called "C-c ]" paredit-forward-barf-sexp
   ;; point was always at the "h" in hello
   ((hello this is a nice little sentence))
   ((hello this is a nice little) sentence)
   ((hello this is a nice) little sentence)
   ((hello this is a) nice little sentence)
   ((hello) this is a nice little sentence)


   ;; here I've called paredit-backward-barf-sexp
   ;; point was always at the "e" in sentence
   ((hello this is a nice little sentence))
   (hello (this is a nice little sentence))
   (hello this (is a nice little sentence))
   (hello this is (a nice little sentence))
   (hello this is a (nice little sentence))
   (hello this is a nice (little sentence))
   (hello this is a nice little (sentence))
   (hello this is a nice little sentence())

       #+END_SRC


   Paredit
   #+BEGIN_SRC emacs-lisp

   #+END_SRC

*** paredit-splice-sexp
This removes the parentheses around the current sexpression
#+BEGIN_SRC emacs-lisp
(cool (cool (cool (cool (cool)))))
(cool (cool (cool (cool (cool)))))
(cool (cool (cool (cool (cool)))))
(cool (cool (cool (cool (cool)))))
(cool (cool (cool (cool (cool)))))

#+END_SRC
** Restclient mode
  install restclient. It lets you query the server via get and post.  I can view the results via emacs!
** sunrise-commander is a dired derived mode that acts like filezilla inside emacs.
   =C= copy the current file into the other directory
   =C-u C= copy the current file/files into the other directory in a background process
** ediff
   Ediff is emacs's cool way of camparing two files.  It's very cool.
*** Commands
   - =a= copies buffer a diff to buffer b
   - =b= copies buffer b diff to buffer a
   - =A= toggles readonly mode of buffer a
   - =B= toggles readonly mode of buffer b
   - =wa= save buffer a
   - =wb= save buffer b
   - =!= update the differance regions.  If you press =a= and =b= multiple times, you should probably do a =!=
   - =*= highlights the words in the diff region that differ
   - =ra= restore the diff region in buffer a
   - =rb= restore the diff region in buffer b
   - =z= suspend the ediff session
   - =s= make the merge buffer as small as possible

   When you specify files, you can edit the files as root using tramp's syntax like this.

   /su::/path/to/file
** tramp is an emacs extension that lets you edit remote files
  it's syntax is done by pressing C-x C-f (find-file) then typing one of the following:

     /METHOD:USER@HOST:FILENAME
     /METHOD:USER@HOST#PORT:FILENAME


     method can be ftp, ssh, rlogin, or telnet

     If ssh-agent is running, Emacs uses scp.  This probably is a clue about how to use ssh without a password.
      I need to use scp
** etags
Etags is Emacs solution to creating elisp based tagging in Emacs.  It is the prefect tagging system for your init files.

The shell command Etags needs to be run to generate a TAGS file.  This looks like ~etags files~ or ~COMMAND | etags -~

The simple way to do it is, which finds certain types of files and throws them in the TAGS file.

#+BEGIN_SRC sh :results output :exports both :dir ~/.emacs.d/
find . -wholename "*lisp/[a-zA-Z-]*.el" -print | etags -
#+END_SRC

#+RESULTS:

The command ~(xref-find-definitions)~ does the rest.  I bind it like so:


~(global-set-key (kbd "C-c .") #'xref-find-definitions)~

** auto-insert mode
Auto-insert mode is a minor mode that will automatically populate a newly created file with default text.  It is bundled with Emacs.
*** Set up auto insertion
Since autoinsert mode is bundled with Emacs, enabling it is trivial.  Simply, require the autoinsert library, and when you open up an empty file, perform auto-insertion, if applicable.

#+BEGIN_SRC emacs-lisp
  (require 'autoinsert)
  (add-hook 'find-file-hook 'auto-insert)
#+END_SRC

*** auto-insert variables
- auto-insert-directory
  A string variable that specifies where to look for default file templates to insert into newly created files.

- auto-insert-mode
  Enable auto-insert mode.
Enable autoinsert mode, and do not ask me if I want to perform automatic insertion.  Just do it.

- auto-insert-query
  If the value is non-nil, then ask the user if they wish to perform auto-insertion.

- auto-insert-alist
  A list specifying text to insert by default into a new file. Elements look like (CONDITION . ACTION) or ((CONDITION . DESCRIPTION) . ACTION). CONDITION may be a regexp that must match the new file's name, or it may be a symbol that must match the major mode for this element to apply. Only the first matching element is effective. Optional DESCRIPTION is a string for filling `auto-insert-prompt'. ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute file-name or one relative to `auto-insert-directory' or a function to call. ACTION may also be a vector containing several successive single actions as described above, e.g. [\"header.insert\" date-and-author-update].

#+BEGIN_SRC emacs-lisp
  (setq auto-insert-alist '((web-mode . my/yas-web-mode-snippet)
                            (org-mode . my/yas-org-snippet)))
#+END_SRC

An minimal working setup of autoinsert-mode might look like this:

#+BEGIN_SRC emacs-lisp
  (require 'autoinsert)
  (add-hook 'find-file-hook 'auto-insert)
  (setq auto-insert-directory "~/.emacs.d/auto-insert-directory/")
  (setq auto-insert-mode t
        auto-insert-query nil)

  (setq auto-insert-alist '((web-mode . my/web-mode-template-function)
                            (org-mode . "my-default-org-mode-file.org")
                            (text-mode . ["my-default-org-mode-file.org" my/finishing-function])))

#+END_SRC

*** Use Snippets instead of templates

Insertion of template files into buffers is cool, but auto-insert mode is more powerful than than.  One can expand a yasnippet into a newly created file.  For example, if you write your Emacs init file in several org-mode files in "~/.emacs.d/lisp/", then you could insert a snippet specific to your Emacs configuration.  The following does this.

#+BEGIN_SRC emacs-lisp
  (defun my/yas-elisp-init-files-snippet ()
    (interactive)
    (yas-expand-snippet (yas-lookup-snippet "<elisp-init-files")))
#+END_SRC

#+BEGIN_SRC emacs-lisp
(add-to-list 'auto-insert-alist '((".*/lisp/.*\\.org$") . [my/yas-elisp-init-files-snippet]))
#+END_SRC
*** Set up yasnippet

Inserting a predefined snippet via Emacs lisp is defined [[http://joaotavora.github.io/yasnippet/snippet-expansion.html#sec-1-6][here]].  In case you don't like reading, then just do the following:

~(yas-expand-snippet (yas-lookup-snippet "SnippetName"))~

I'm defining some functions that will automatically expand when I open a file.  Cool eh?
#+BEGIN_SRC emacs-lisp
  (defun my/yas-org-snippet ()
    (interactive)
    (yas-expand-snippet (yas-lookup-snippet "<org")))

  (defun my/yas-elisp-init-files-snippet ()
    (interactive)
    (yas-expand-snippet (yas-lookup-snippet "<elisp-init-files")))


  (defun my/yas-web-mode-snippet ()
    (interactive)
    (yas-expand-snippet (yas-lookup-snippet "<web-mode")))
#+END_SRC

** calc

Emacs calc mode is amazing!  It can do all sorts of things.  Just reading the manual will make your head swim!

To open it type M-x calc  Or C-x * c.  The latter command is cooler, because it lets you toggle calc's visibility.

*** How to solve systems of equations



First enter into Algebraic mode via "m a"

Enter a vector of equations

So we can put this into Emacs calc via:

' [43 = 8b + 0o, 19 = 0.5b + 5o] RET

"a S b, o RET" will solve the equation.

The answer will look like:

=[b = 5.375, o = 3.2625]=


* Regexp
  Regular expressions are nifty ways of searching/replacing regions of text.

  Consider this example

  #+BEGIN_SRC php
    if (isadmin() || ismanager ()) {
        //some code here
    }
  #+END_SRC

  Suppose that you want to add a space between both "is" in the function names.  The following will do just that.

  ~M-x dired-do-query-replace-regexp is\(admin\|manager\) RET is \1 RET~

  But let's get a basic understanding of regexps.

* some nice emacs add on modes/APIs that make elisp programming nice
- ctable https://github.com/kiwanami/emacs-ctable
- s https://github.com/magnars/s.el
- f https://github.com/rejeep/f.el
* Elisp macro add-function
  This is the old way of doing it. The newer was is to say add-function
* debugging weird errors
** wrong type argument errors

If you get a weird error like "wrong type argument : arrayp , nil", or "wrong type argument : stringp", it might be an issue with package.el.  The following might fix the error:

# This may copywrited!
# http://emacs.stackexchange.com/questions/17823/wrong-type-argument-arrayp-nil
- Change the address for the melpa archive to: "http://melpa.org/packages"
- Delete the ~/.emacs.d/elpa/archives/melpa/archive-contents file

 #+BEGIN_SRC sh
 rm ~/.emacs.d/elpa/archives/melpa/archive-contents
 #+END_SRC
- Run package-initialize and package-refresh-contents.

  #+BEGIN_SRC emacs-lisp
  (package-initialize)
  (package-refresh-contents)
  #+END_SRC

  #+RESULTS:
** debugging your init file
   https://github.com/Malabarba/elisp-bug-hunter.  This is SOOO helpful!
   M-x bug-hunter-init-file RET e
** Variable binding depth exceeds max-specpdl-size
   Check out this stackoverflow question:
   http://stackoverflow.com/questions/1322591/tracking-down-max-specpdl-size-errors-in-emacs

   #+BEGIN_SRC emacs-lisp
     ;;   To track the problem down, you can try this:

     (setq max-specpdl-size 5)  ; default is 1000, reduce the backtrace level
     (setq debug-on-error t)    ; now you should get a backtrace
     ;; C-h a ; in speedbar
   #+END_SRC

   #+RESULTS:
   : t

   to go back to the state that you wanted again, you can do this:

   #+BEGIN_SRC emacs-lisp
     (setq max-specpdl-size 2580)  ; default is 1000, reduce the backtrace level
     (setq debug-on-error nil)    ; now you should get a backtrace
   #+END_SRC

   #+RESULTS:
* java development

You will probably want to use eclim  https://github.com/ervandew/eclim

It turns eclipse into a server.  Emacs sends info to that server, the server responds back, and Emacs shows you code errors, code completion, etc.  It's probably the best way to do java development in Emacs.
* building Emacs
--with-cairo builds Emacs with the ability to render Emacs with Cairo.  Cairo is a 2D drawing library.  It is failing its own test suite.  So it might not be a great thing for Emacs.  And currently it doesn't work so well.

sudo ../emacs-src/configure --with-modules --enable-link-time-optimization  --with-x-toolkit=gtk3 --with-xwidgets
* connecting to a database
:PROPERTIES:
:engine: mysql
:dbhost: localhost
:dbuser: joshua
:dbpassword: password
:database: wordpress
:END:

#+BEGIN_SRC sql :results replace :exports both
SELECT user_login, display_name FROM wpHonorsCollege_users WHERE ID = 1
#+END_SRC

#+RESULTS:
| user_login | display_name |
|------------+--------------|
| joshua     | joshua       |

#+BEGIN_SRC js :results output
console.log (6 + 2)
#+END_SRC

#+RESULTS:
: 8

#+BEGIN_SRC python :results output
print (3 + 8)
#+END_SRC

#+RESULTS:
: 11

#+BEGIN_SRC emacs-lisp
(+ 2 4 )
#+END_SRC

#+RESULTS:
: 6

#+BEGIN_SRC sh :results output :exports both
ls
#+END_SRC
* debugging emacs crashes
https://www.gnu.org/software/emacs/manual/html_node/emacs/Crashing.html

Essentially you do this:

#+BEGIN_SRC sh
cd /path/to/emacs/src
gdb ./emacs
...
(gdb) run
#+END_SRC

Now you use Emacs as usual when it crashes... you run

#+BEGIN_SRC sh
(gdb) thread apply all bt

#+END_SRC
* tweaking the Gnus manual, because it is super confusing!

Make the [[info:gnus#Maildir][info:gnus#Maildir]] section readable, because it is not!

https://emacs.stackexchange.com/questions/34274/gnus-gmail-and-mbsync-do-i-need-dovecot
* get company ebdb to work.

I basically need to bind tab to company-ebdb in
* TODO getting emacs better performance on remote files
:LOGBOOK:
- State "TODO"       from              [2020-02-25 Tue 10:26]
:END:

This is really weird!

It seems that helm-mode is causing a really slow performance on opening and saving remote files.

https://emacs.stackexchange.com/questions/5359/how-can-i-troubleshoot-a-very-slow-emacs



What can cause this problem? Is it caused by Emacs or it is due to my
pc's performance? Generally what are the variables that affect Emacs'
performance?

Emacs has around 50,000 internal variables and a few thousand external
packages averaging at a few dozen variables each, you can't expect
someone to answer this in a general sense. :-)

You can see that just by looking at the comments thread under your
question. There are half a dozen different suggestions in there, all
equally valid.  What can you do to pinpoint the problem?  Option 1:
Disable modes

Start disabling those minor-modes you've listed, and see which one
solves you performance issue. I would start with smartparens,
auto-complete, line-number and font-lock, and then follow down the
list.

"I didn't have this problem yesterday" means very little, don't rely
on it too heavily. Just start disabling minor-modes until something
solves it.

If none of the minor-modes fix your issue, then start commenting out
portions of your init file until you find out which snippet was
causing this. In any case, ask a new question when you have something
more specific.  Option 2: The profiler

    Invoke M-x profiler-start RET RET (the second RET is to confirm
    cpu); Do some typing, preferably an entire paragraph or more;
    Invoke M-x profiler-report.

That will give you a buffer describing the cpu time taken by each
function. Hitting TAB on a line expands it to display the functions
inside it. Navigate this buffer until you find out which function is
taking so much CPU time.  What do I do afterwards?

Once you find the function or package or snippet causing lag you can
(in no particular order):

Ask a new question here regarding that specific minor-mode (or
function or snippet).  Report a bug to the package maintainer.  Check
the comments at the top of the package's source file. If it contains a
URL (specially on github), there's probably an issue tracker there.
Some packages offer a command like M-x PACKAGE-bug-report.  His or her
email should be at the top of the package's source file.  If it's a
built-in package, you can report it with M-x report-emacs-bug.  Even
for packages that are not built-in, you can ask for help at the
help-gnu-emacs mailing list.
* cool Emacs projects I should try 
** Set up Emacs to send html emails via org-mime and set up polymode

   Set up part of the message-mode in org-mode.
   
   polymode

  org-mode message-mode 

  #+BEGIN_SRC scheme
    (define (hello)
      (let ([a "b"])
        b))
  #+END_SRC

  #+RESULTS:
*** DONE Set up poly such that I see org-mode formatting in message mode
    CLOSED: [2020-08-12 Wed 00:07]
    :LOGBOOK:
    - State "DONE"       from "TODO"       [2020-08-12 Wed 00:07]
    - State "TODO"       from              [2020-08-11 Tue 23:41]
    :END:
*** Stop org-mode from hiding my footer when I press tab
*** Let C-c C-c send the email, when I am C-c C-c doesn't do anything for org-mode 

    For instance

    To: jbranso@dismail.de
    
    --message follows this line--
   
   when point is HERE and I press C-c C-c, then send the email 
 
   #BEGIN_SRC scheme
    (define a "b") 
    ;; when point is here, and I press C-c C-c, evaluate the code
   #+END_SRC 

   --

   Sent from Emacs and Gnus
*** lazily load poly-message-mode 
*** set up poly-message-mode on message mode by default 

    This is slightly harder to do, because poly-mode tries to set up poly-mode via auto-mode-alist

    (add-to-list 'auto-mode-alist '("\\.md" . poly-markdown-mode))

   or    // -*- mode: poly-noweb -*- 
*** customize my html output to make it look SUPER COOL! 
   Org-mode renders the HTML 
**** create an org html template for use in emails
* migrating to emacs 27.1 

  I can now use .config/emacs/init.el
  
  #+BEGIN_SRC sh :results output :exports both
  mv .emacs.d/ .config/emacs
  #+END_SRC
** get flycheck-pos-tip working again
** emacs-seq is breaking things.  Specifically M-x bug-hunter does not work

;; mroh
;;11:45:29
;; joshuaBPMan: try to remove the emacs-seq pkg.

;;mroh
;;11:51:32
;;joshuaBPMan: it's included in emacs, so require works. Do you have any of those `guix refresh -l emacs-seq` installed?

;; cd .guix-profile; grep -r 'seq'
;; shows emacs-seq in my manifest
;; cat .guix-profile/manifest   shows that emacs-seq is a dependency of bug-hunter...removing bug-hunter

;;Building the following 5 packages would ensure 9 dependent packages are rebuilt:
;;emacs-erc-status-sidebar@0.1-1.ea4189a
;;jmacs@27.1
;;emacs-flycheck-haskell@0.8-2.32ddff8
;;emacs-psc-ide@0.1.0-1.7fc2b84
;;emacs-org-roam@1.2.1
** Also it would be nice if org-babel-load-file would "log" in Messages, which heading it is currently loading, so that debugging 
   org-babel emacs files would be easier.
* things I can do 
** file a bug report for Emacs org-mode...Somewhere in my org-mode gtd.org file, I am causing a syntax error.

   Where is it?
